import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { DishService } from '@/services/dishService';

// 移除缓存配置
// export const revalidate = 30;

// GET /api/dishes
export async function GET() {
  try {
    console.log('API route: Starting request...');
    
    // 使用静态方法
    const dishes = await DishService.getAllDishes();
    console.log('API route: Fetching dishes...');

    return NextResponse.json(dishes);
  } catch (error) {
    console.error('API route error:', error);
    return NextResponse.json(
      { error: '获取菜品列表失败' },
      { status: 500 }
    );
  }
}

// POST /api/dishes
export async function POST(request: NextRequest) {
  try {
    const data = await request.json();
    const newDish = await DishService.createDish(data);
    return NextResponse.json(newDish);
  } catch (error) {
    return NextResponse.json(
      { error: '创建菜品失败' },
      { status: 500 }
    );
  }
} 